package com.yootk;

import java.util.concurrent.ThreadFactory;

class YootkThreadFactory implements ThreadFactory {
    private static final ThreadFactory INSTANCE = new YootkThreadFactory();
    private static final String TITLE = "yootk--"; // 定义线程标记名称
    private static int count = 0; // 线程个数统计

    private YootkThreadFactory() {} // 构造方法私有化

    public static ThreadFactory getInstance() { // 获取本类实例
        return INSTANCE;
    }

    @Override
    public Thread newThread(Runnable run) {
        return new Thread(run, TITLE + count++); // 获取线程实例
    }
}

public class YootkDemo {
    public static void main(String[] args) throws Exception {
        Thread thread = YootkThreadFactory.getInstance().newThread(() -> { // 获取线程对象
            System.out.println("多线程执行，" + Thread.currentThread().getName());
        });
        thread.start(); // 线程启动
    }
}